package com.linkedin.ranker;

import java.util.*;
import java.io.*;
import java.util.Scanner;


public class Model
{
	public String getEvents()
	{
		StringBuilder contents = new StringBuilder();
		final String aFile="/Users/anagpal/events.txt";

		/*
		 * nodes:[
    {nodeName:"Myriel", group:1},
    {source:1, target:0, value:1},
		 */
		try {
			//use buffering, reading one line at a time

			BufferedReader input =  new BufferedReader(new FileReader(aFile));

			String line = "["; //not declared within while loop
			/*
			 * readLine is a bit quirky :
			 * it returns the content of a line MINUS the newline.
			 
			 */
			//contents.append(line);
			while (( line = input.readLine()) != null){
				StringTokenizer st = new StringTokenizer(line);
				contents.append(line);
				contents.append(",");
			}
				
			
			//contents.append("]");
			input.close();

		}
		catch (IOException ex){
			ex.printStackTrace();
		}

		String retval= contents.toString();
		return retval.substring(0,retval.length()-2);
	}
	
	
	public String getNodes()
	{
		StringBuilder contents = new StringBuilder();
		final String aFile="/Users/anagpal/page_flow_nodes.txt";

		/*
		 * nodes:[
    {nodeName:"Myriel", group:1},
    {source:1, target:0, value:1},
		 */
		try {
			//use buffering, reading one line at a time

			BufferedReader input =  new BufferedReader(new FileReader(aFile));

			String line = "["; //not declared within while loop
			/*
			 * readLine is a bit quirky :
			 * it returns the content of a line MINUS the newline.
			 
			 */
			int lc=0;
			contents.append(line);
			while (( line = input.readLine()) != null){
				lc++;
				StringTokenizer st = new StringTokenizer(line);
				int count=1;
				while(st.hasMoreTokens()) {
					String source = st.nextToken();
					
					if(count==1)
					{
						int group=lc/6;
						contents.append("{nodeName:\""+source+"\",group:"+group+"},");
						contents.append(System.getProperty("line.separator"));
						count++;
					}
				}
				
			}
			contents.append("]");
			input.close();

		}
		catch (IOException ex){
			ex.printStackTrace();
		}

		return contents.toString();
	}

}
		